package cn.icanci.loopstack.plugin.dalgen.intercept.impl;

import cn.icanci.loopstack.plugin.dalgen.intercept.CustomEngine;
import cn.icanci.loopstack.plugin.dalgen.model.ClassInfoVO;
import cn.icanci.loopstack.plugin.dalgen.model.ConfigurationInfoVO;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author icanci
 * @since 1.0 Created in 2022/05/13 21:02
 */
public class DataMdImpl implements CustomEngine {

    private static final String SPACER            = File.separator;

    private static final String SRC_MAIN_RESOURCE = SPACER + "src" + SPACER + "main" + SPACER + "resources" + SPACER;

    @Override
    public void handle(ConfigurationInfoVO config, List<ClassInfoVO> classInfos) {
        Map<String, Object> params = new HashMap<>();
        params.put("config", config);
        params.put("classInfos", classInfos);

        // 构建文件地址
        String filePath = config.getRealProjectCodePath() + SRC_MAIN_RESOURCE + "DataSource.md";
        try {
            execute(params, "code-generator/markdown-file/DataMd.ftl", filePath);
        } catch (IOException | TemplateException e) {
            e.printStackTrace();
        }

        System.out.println("=== Data Sql Md Part Build Complete.=== ");
    }

}
